home *** CD-ROM | disk | FTP | other *** search
- /* 4567890123456789012345678901234567890123456789012345678901234567 */
- /*
- * File: About.c
- * Author: Mark H. Linton
- * Creation Date: 2/4/95
- * Modification Date:
- * Description: A routine which may be used to handle the
- * "About <application name>" item in the apple
- * menu.
- */
- #include <Dialogs.h>
- #include <Resources.h>
- #include <TextEdit.h>
- #include <Memory.h>
-
- #include "About.h"
- #include "Toolbox.h"
-
- pascal Boolean DialogEventFilter(DialogPtr aDialog,
- EventRecord *anEvent, short *anItem);
-
- Rect theTextPaneRect;
- TEHandle theTextPane;
-
- void DoAbout(short anIdentifier) {
- DialogPtr theDialog;
- short theItem, itemCount;
- Boolean done = false;
- short theType;
- Handle theHandle;
- Rect theRect;
- Handle theText;
- StScrpHandle theStyle;
- GrafPtr theCurrentPort;
- short theItemHit;
- long theLastLine;
- short theTextHeight, thePaneHeight;
-
- theDialog = GetNewDialog(anIdentifier, nil, kInFront);
- if (theDialog != nil) {
- GetPort(&theCurrentPort);
- #if STRICT_WINDOWS
- SetPortWindowPort(theDialog);
- #else
- SetPort(theDialog);
- #endif
- #define kTextPane 3
- GetDialogItem(theDialog, kTextPane, &theType, &theHandle,
- &theTextPaneRect);
- theTextPane = TEStyleNew(&theTextPaneRect, &theTextPaneRect);
- theStyle = (StScrpHandle)GetResource('styl', anIdentifier);
- theText = GetResource('TEXT', anIdentifier);
- HLock(theText);
- TEStyleInsert(*theText, GetHandleSize(theText), theStyle,
- theTextPane);
- HUnlock(theText);
- theLastLine = (**theTextPane).nLines;
- theTextHeight = TEGetHeight(theLastLine, 1, theTextPane);
- thePaneHeight = theTextPaneRect.bottom - theTextPaneRect.top;
- (**theTextPane).destRect.bottom =
- (**theTextPane).destRect.top + theTextHeight - thePaneHeight;
- (void)SetDialogDefaultItem(theDialog, ok);
- (void)SetDialogCancelItem(theDialog, ok);
- (void)SetDialogTracksCursor(theDialog, true);
- #if STRICT_WINDOWS
- ShowWindow(GetDialogWindow(theDialog));
- #else
- ShowWindow(theDialog);
- #endif
- DrawDialog(theDialog);
- SetEventMask(everyEvent);
- do {
- ModalDialog((ModalFilterProcPtr)DialogEventFilter,
- &theItemHit);
- } while (theItemHit != ok && theItemHit != cancel);
- #if STRICT_WINDOWS
- HideWindow(GetDialogWindow(theDialog));
- #else
- HideWindow(theDialog);
- #endif
- itemCount = CountDITL(theDialog);
- for (theItem = 1; theItem <= itemCount; theItem++) {
- GetDialogItem(theDialog, theItem,
- &theType, &theHandle, &theRect);
- if ((theType == picItem) ||
- (theType == (picItem + itemDisable))) {
- ReleaseResource(theHandle);
- }
- }
- DisposeDialog(theDialog);
- SetPort(theCurrentPort);
- }
- }
-
- pascal Boolean DialogEventFilter(DialogPtr aDialog,
- EventRecord *anEvent, short *anItem) {
- GrafPtr theCurrentPort;
- ModalFilterProcPtr StandardFilter;
- Boolean eventWasHandled;
- static long theLastTime = 0;
- long theTime = TickCount();
- #define kTicksToWait 10
- #define kQuickTicksToWait 0
- long ticksToWait = kTicksToWait;
-
- GetPort(&theCurrentPort);
- #if STRICT_WINDOWS
- SetPortWindowPort(aDialog);
- #else
- SetPort(aDialog);
- #endif
- switch (anEvent->what) {
- case updateEvt:
- #if STRICT_WINDOWS
- if ((WindowRef)anEvent->message == (WindowRef)aDialog) {
- BeginUpdate(GetDialogWindow(aDialog));
- UpdateDialog(aDialog, GetWindowPort(GetDialogWindow(aDialog))->visRgn);
- #else
- if ((WindowPtr)anEvent->message == aDialog) {
- BeginUpdate(aDialog);
- UpdateDialog(aDialog, aDialog->visRgn);
- #endif
- TEUpdate(&theTextPaneRect, theTextPane);
- #if STRICT_WINDOWS
- EndUpdate(GetDialogWindow(aDialog));
- #else
- EndUpdate(aDialog);
- #endif
- }
- break;
- default:
- if ((anEvent->modifiers & optionKey) == 0) {
- ticksToWait = kTicksToWait;
- } else {
- ticksToWait = kQuickTicksToWait;
- }
- if (theTime > (theLastTime + ticksToWait)) {
- TEScroll(0, -1, theTextPane);
- theLastTime = theTime;
- }
- break;
- }
- if (GetStdFilterProc(&StandardFilter) == noErr) {
- eventWasHandled = StandardFilter(aDialog, anEvent, anItem);
- }
- SetPort(theCurrentPort);
- return eventWasHandled;
- }
-